<template>
	<view class="prodcut-list-wrap" :data-theme="theme()" :class="theme() || ''">
		<view class="point_top">
			<!-- <image src="../../../../static/point_bg.png" mode=""></image> -->
			<view class="tc pr">
				<view class="f60 fb white">{{ my_points }}</view>
				<view class="f26 white">我的积分</view>
			</view>
		</view>
		<view class="p-0-20 bg-white f32 gray3 fb ponit_title">好物兑换</view>

		<view class="list">
			<view class="item" v-for="(item, index) in listData" :key="index" @click="gotoList(item)">
				
				<image class="product-cover" :src="item.imagePath" mode="aspectFit"></image>
				<view class="product-info flex-1">
					<view class="product-title">{{ item.productName }}</view>
					<view class="already-sale d-b-c">
						<text>还剩{{ item.stock }}件</text>
					</view>
					<view class="price">
						<text class="num">{{ item.sku[0].pointNum }}</text>
						<text class="f26">积分</text>
						<template v-if="item.sku[0].pointMoney != 0">
							<text class="f30">+</text>
							¥
							<text class="num">{{ item.sku[0].pointMoney }}</text>
						</template>
					</view>
				</view>
				<view class="d-c-e jifen">
					<view class="point_btn" :class="item.stock > 0 ? '' : 'btn-gray'">兑换</view>
				</view>
			</view>
		</view>

		<!-- 没有记录 -->
		<view class="d-c-c p30" v-if="listData.length == 0 && !loading">
			<text class="iconfont icon-wushuju"></text>
			<text class="cont">亲，暂无相关记录哦</text>
		</view>
		<uni-load-more v-else :loadingType="loadingType" class="jifen-point"></uni-load-more>
	</view>
</template>

<script>
	import uniLoadMore from '@/components/uni-load-more.vue';
	export default {
		components: {
			uniLoadMore
		},
		data() {
			return {
				/*是否加载完成*/
				loading: true,
				/*数据列表*/
				listData: [],
				/*最后一页码数*/
				last_page: 0,
				/*当前页面*/
				page: 1,
				/*每页条数*/
				list_rows: 10,
				no_more: false,
				my_points: 0
			};
		},
		onShow() {
			this.page = 1;
			this.listData = [];
			this.getData();
		},
		computed: {
			/*加载中状态*/
			loadingType() {
				if (this.loading) {
					return 1;
				} else {
					if (this.listData.length != 0 && this.no_more) {
						return 2;
					} else {
						return 0;
					}
				}
			}
		},
		onReachBottom() {
			let self = this;
			if (self.page < self.last_page) {
				self.page++;
				self.getData();
			}
			self.no_more = true;
		},
		methods: {
			/*获取数据*/
			getData() {
				let self = this;
				self.loading = true;
				self._postBody(
					'plus/points/product/index', {
						pageIndex: self.page || 1,
						pageSize: self.list_rows
					},
					function(res) {
						self.loading = false;
						self.listData = self.listData.concat(res.data.list.records);
						self.my_points = res.data.points;
						self.last_page = res.data.list.lastPage;
						if (res.data.list.lastPage <= 1) {
							self.no_more = true;
						}
					}
				);
			},

			/*跳转产品列表*/
			gotoList(e) {
				if (e.stock > 0) {
					this.gotoPage('/pages/plus/points/detail/detail?pointProductId=' + e.pointProductId);
				} else {
					this.showSuccess('该商品已售完');
				}
			}
		}
	};
</script>

<style lang="scss">
	page {
		background-color: #ffffff;
	}
	::v-deep .jifen-point .load-more {
		background: rgb(242,242,242);
	}
	.point_top {
		position: relative;
		width: 750rpx;
		height: 240rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		background-color: #ff5704;
	}

	.point_top image {
		position: absolute;
		width: 750rpx;
		height: 240rpx;
		z-index: 0;
	}

	.prodcut-list-wrap .list {
		background: #f2f2f2;
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		flex-wrap: wrap;
		padding: 0 20rpx;
		padding-top: 20rpx;
		width: calc(100% - 40rpx);
			
	}

	.ponit_title {
		height: 80rpx;
		line-height: 80rpx;
	}

	.prodcut-list-wrap .list .item {
		width: 345rpx;
		margin-bottom: 20rpx;
		padding-bottom: 20rpx;
		overflow: hidden;
		background: #ffffff;
		border-radius: 12rpx;
		position: relative;
	}
	.jifen{
		display: flex;
		justify-content: flex-end;
		position: absolute;
		right: 0;
		bottom: 20rpx;
	}

	.prodcut-list-wrap .product-cover  {
		width: 345rpx;
		height:  345rpx;
		border-radius: 12rpx;
	}

	.prodcut-list-wrap .product-info {
		flex: 1;
		margin-top: 10rpx;
		margin-bottom: 60rpx;
		margin-left: 26rpx;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
	}

	.prodcut-list-wrap .product-title {
		display: -webkit-box;
		overflow: hidden;
		-webkit-line-clamp: 2;
		-webkit-box-orient: vertical;
		font-size: 32rpx;
	}

	.prodcut-list-wrap .price {
		color: #f6220c;
		font-size: 20rpx;
		line-height: 28rpx;
	}

	.prodcut-list-wrap .price .num {
		padding: 0 4rpx;
		font-size: 36rpx;
	}

	.prodcut-list-wrap .already-sale {
		color: #999;
		font-size: 26rpx;
		margin-bottom: 18rpx;
	}

	.prodcut-list-wrap .already-sale .btn-red {
		line-height: 2;
		font-size: 28rpx;
	}

	.point_btn {
		width: 120rpx;
		height: 50rpx;
		background: #ff5704;
		border-radius: 25rpx;
		font-size: 26rpx;
		color: #ffffff;
		line-height: 50rpx;
		text-align: center;
		margin-right: 30rpx;
	}

	.point_btn.btn-gray {
		background: #cccccc;
		color: #ffffff;
	}

	.u-waterfall {
		display: flex;
		flex-direction: row;
		align-items: flex-start;
	}

	.u-column {
		display: flex;
		flex: 1;
		flex-direction: column;
		height: auto;
	}

	.u-image {
		width: 100%;
	}
</style>